import { reqCategoryList,reqGetBannerList,reqFloorList} from '@/api'
//home模块的小仓库
const state = {
    // 此处的数据要根据接口返回值来进行相应的初始化 三级分类的数据
    categoryList: [],
    // 轮播图的数据
    bannerList:[],
    // floor组件的数据
    floorList:[]
}
const actions = {
    async categoryList(context) {
        // 此处await为可以拿到reqCategoryList()函数返回的promise对象成功状态的值
        let result = await reqCategoryList()
        if (result.code === 200) {
            context.commit('CATEGORYLIST', result.data)
        }
    },

    async getBannerList(context){
        let banner = await reqGetBannerList()
        if(banner.code === 200){
            context.commit('GETBANNERLIST',banner.data)
        }
    },

    async getFloorList(context){
        let floor = await reqFloorList()
        if(floor.code === 200){
            context.commit('GETFLOORLIST',floor.data)
        }
    }
}
const mutations = {
    CATEGORYLIST(state, categoryLists) {
        categoryLists.forEach(categoryList => {
            if (state.categoryList.length != 16) {
                state.categoryList.push(categoryList)
            }
        });
    },
    GETBANNERLIST(state,bannerList){
        state.bannerList = bannerList
    },

    GETFLOORLIST(state,floorList){
        state.floorList = floorList
    }

}
const getters = {
    
}

export default {
    state,
    actions,
    mutations,
    getters
}